import json


def main():
    valid_conbinations = {}
    with open("data.txt", "r") as reader:
        for line in reader:
            voca = []
            # words = line.strip().replace('\t','').replace('\n','').split(" ")
            words = line.strip().replace('\n','').split("\t")
            # newwords = [w for w in words]
            # newwords = newwords[1:-1]
            # print(newwords)
            # print("\n")
            first_word = words[0].strip()
            for w in words[1:]:
                if len(w) > 0:
                    w = w.strip()[len(first_word):]
                    # voca.append(w.strip()[1:-1])
                    voca.append(w)
            valid_conbinations[first_word] = voca
#    print(valid_conbinations)
    with open("pinyin.json", 'w') as writer:
        json.dump(obj=valid_conbinations, fp=writer, indent=0)

            



if __name__ == '__main__':
    main()